package com.wl.controller;

import com.wl.pojo.Comment;
import com.wl.service.CommentService;
import com.wl.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 对文章发表评论的接口
     */
    @PostMapping
    public Result sendComment(@RequestBody Comment comment) {
        return Result.success(commentService.sendComment(comment));
    }

    /**
     * 获取文章评论
     */
    @GetMapping
    public Result getPostCommentsByPostId(Integer postId) {
        return Result.success(commentService.getPostCommentsByPostId(postId));
    }

    /**
     * 查询当前用户对某篇文章下面评论的点赞情况
     */
    @GetMapping("/get/likes")
    public Result getUserLikesComment(@RequestParam Integer userId, @RequestParam Integer postId) {
        return Result.success(commentService.getUserLikesComment(userId, postId));
    }

    /**
     * 点赞某条评论
     */
    @PostMapping("/like")
    public Result likeComment(@RequestParam Integer userId, @RequestParam Integer id) {
        commentService.likeComment(userId,id);
        return Result.success();
    }

    /**
     * 取消点赞某条评论
     */
    @PostMapping("/cancel/like")
    public Result cancelLikeComment(@RequestParam Integer userId, @RequestParam Integer id) {
        commentService.cancelLikeComment(userId,id);
        return Result.success();
    }

    /**
     * 删除顶级评论
     */
    @DeleteMapping
    public Result deleteComment(@RequestBody List<Integer> ids) {
        commentService.deleteComment(ids);
        return Result.success();
    }
}
